# -*- coding: utf-8 -*-
# @Time : 2022/6/20 12:01
# @Author : cheney
# @File : data.py
# @Software: PyCharm
# @Site: www.cheney.cc

"""
    数据类型的结构，返回用
"""
import json


class data:
    type = 0
    sensor_list = []  # 传感器编号列表
    data_list = []  # 传感器数据列表
    trace_stack = []  # 小车轨迹栈

    """下面是类型字段的取值，标识数据类型，对外透明"""
    DATA_DEFAULT = 0
    DATA_SENSOR = 1
    DATA_TRACE = 2
    DATA_TRACE_AND_TRACE = 3

    def __init__(self, sensor_list=None, data_list=None, trace_stack=None):
        """
        构造函数
        :param sensor_list:
        :param data_list:
        :param trace_stack:
        """
        if trace_stack is None:
            trace_stack = []
        if data_list is None:
            data_list = []
        if sensor_list is None:
            sensor_list = []
        self.sensor_list = sensor_list
        self.data_list = data_list
        self.trace_stack = trace_stack

    def set_type(self, type_):
        self.type = type_

    def set_data_list(self, data_list):
        self.data_list = data_list

    def set_trace_stack(self, trace_stack):
        self.trace_stack = trace_stack

    def set_dst_pi_id(self):
        pass

    def from_json(self, data_json: json, encoding: str = 'utf-8'):
        # self. = data_json["direction"]
        # todo:完善
        pass

    def to_json(self) -> json:
        _ans = {
            "sensor_list": self.sensor_list,
            "data_list": self.data_list,
            "trace_stack": self.trace_stack,
        }

        return str(json.dumps(_ans))

